import { defineStore } from 'pinia'
import {ref} from "vue";
import user from '../apis/user';

export const useAppStore = defineStore('app', () => {
    const appConfig = ref({
      showMenu: true
    })
    
    function updateAppConfig(data:any) {
      appConfig.value = data;
    }

    function showMenu(isShow:boolean){
      appConfig.value.showMenu = isShow;
    }

    async function fetchAppConfig(){
      try {
        const ret = await user.getUserInfo();
        if(ret.code == 0){
          appConfig.value = ret.data;
        }
      } catch (error) {
        return error
      }
    }
  
    return { appConfig, updateAppConfig, fetchAppConfig, showMenu }
})